.TH std::abs(std::complex) 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::abs(std::complex) \- std::abs(std::complex)

.SH Synopsis
   Defined in header <complex>
   template< class T >
   T abs( const complex<T>& z );

   Returns the magnitude of the complex number z.

.SH Parameters

   z - complex value

.SH Return value

   If no errors occur, returns the absolute value (also known as norm, modulus, or
   magnitude) of z.

   Errors and special cases are handled as if the function is implemented as
   std::hypot(std::real(z), std::imag(z)).

.SH Example


// Run this code

 #include <complex>
 #include <iostream>

 int main()
 {
     std::complex<double> z(1, 1);
     std::cout << z << " cartesian is rho = " << std::abs(z)
               << " theta = " << std::arg(z) << " polar\\n";
 }

.SH Output:

 (1,1) cartesian is rho = 1.41421 theta = 0.785398 polar

.SH See also

   arg                returns the phase angle
                      \fI(function template)\fP
   polar              constructs a complex number from magnitude and phase angle
                      \fI(function template)\fP
   abs(int)
   labs               computes absolute value of an integral value (\\(\\small{|x|}\\)|x|)
   llabs              \fI(function)\fP
   \fI(C++11)\fP
   abs(float)
   fabs
   fabsf              absolute value of a floating point value (\\(\\small{|x|}\\)|x|)
   fabsl              \fI(function)\fP
   \fI(C++11)\fP
   \fI(C++11)\fP
                      computes square root of the sum of the squares of two
                      or three
                      \fI(since C++17)\fP given numbers (\\(\\scriptsize{\\sqrt{x^2+y^2}}\\)
                      √
   hypot              x2
   hypotf             +y2
   hypotl             )
   \fI(C++11)\fP            , (\\(\\scriptsize{\\sqrt{x^2+y^2+z^2}}\\)
   \fI(C++11)\fP            √
   \fI(C++11)\fP            x2
                      +y2
                      +z2
                      )
                      \fI(since C++17)\fP
                      \fI(function)\fP
   abs(std::valarray) applies the function abs to each element of valarray
                      \fI(function template)\fP
   C documentation for
   cabs
